package com.lottery.entity;

import com.baomidou.mybatisplus.annotation.*;
import jakarta.validation.constraints.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@TableName("prizes")
public class Prize {
    
    @TableId(type = IdType.AUTO)
    private Long id;
    
    @NotBlank(message = "奖品名称不能为空")
    @TableField("name")
    private String name;
    
    @DecimalMin(value = "0.0", message = "概率不能小于0")
    @DecimalMax(value = "1.0", message = "概率不能大于1")
    @TableField("probability")
    private BigDecimal probability;
    
    @Min(value = 0, message = "数量不能小于0")
    @TableField("quantity")
    private Integer quantity;
    
    @Min(value = 0, message = "剩余数量不能小于0")
    @TableField("remaining")
    private Integer remaining;
    
    @TableField("image_url")
    private String imageUrl;
    
    @TableField("description")
    private String description;
    
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;
    
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;
    
    // 构造函数
    public Prize() {}
    
    public Prize(String name, BigDecimal probability, Integer quantity, String imageUrl, String description) {
        this.name = name;
        this.probability = probability;
        this.quantity = quantity;
        this.remaining = quantity; // 初始剩余数量等于总数量
        this.imageUrl = imageUrl;
        this.description = description;
        this.active = true; // 默认激活
    }
    
    @TableField("is_active")
    private Boolean active = true;
    
    // 业务方法
    public boolean isAvailable() {
        return remaining > 0;
    }
    
    public void decreaseRemaining() {
        if (remaining > 0) {
            remaining--;
        }
    }
    
    // Getters and Setters
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public BigDecimal getProbability() {
        return probability;
    }
    
    public void setProbability(BigDecimal probability) {
        this.probability = probability;
    }
    
    public Integer getQuantity() {
        return quantity;
    }
    
    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }
    
    public Integer getRemaining() {
        return remaining;
    }
    
    public void setRemaining(Integer remaining) {
        this.remaining = remaining;
    }
    
    public String getImageUrl() {
        return imageUrl;
    }
    
    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }
    
    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }
    
    public Boolean getActive() {
        return active;
    }
    
    public void setActive(Boolean active) {
        this.active = active;
    }
}